home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / sbasketb.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  204 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *sbasketb_scroll;
  15. unsigned char *sbasketb_palettebank;
  16. unsigned char *sbasketb_spriteram_select;
  17.  
  18. static int flipscreen = 0;
  19. static struct rectangle scroll_area = { 0*8, 32*8-1, 0*8, 32*8-1 };
  20.  
  21.  
  22.  
  23. /***************************************************************************
  24.  
  25.   Convert the color PROMs into a more useable format.
  26.  
  27.   Super Basketball has three 256x4 palette PROMs (one per gun) and two 256x4
  28.   lookup table PROMs (one for characters, one for sprites).
  29.   I don't know for sure how the palette PROMs are connected to the RGB
  30.   output, but it's probably the usual:
  31.  
  32.   bit 3 -- 220 ohm resistor  -- RED/GREEN/BLUE
  33.         -- 470 ohm resistor  -- RED/GREEN/BLUE
  34.         -- 1  kohm resistor  -- RED/GREEN/BLUE
  35.   bit 0 -- 2.2kohm resistor  -- RED/GREEN/BLUE
  36.  
  37. ***************************************************************************/
  38. void sbasketb_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  39. {
  40.     int i;
  41.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  42.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  43.  
  44.  
  45.     for (i = 0;i < Machine->drv->total_colors;i++)
  46.     {
  47.         int bit0,bit1,bit2,bit3;
  48.  
  49.  
  50.         bit0 = (color_prom[0] >> 0) & 0x01;
  51.         bit1 = (color_prom[0] >> 1) & 0x01;
  52.         bit2 = (color_prom[0] >> 2) & 0x01;
  53.         bit3 = (color_prom[0] >> 3) & 0x01;
  54.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  55.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  56.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  57.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  58.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  59.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  60.         bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  61.         bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  62.         bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  63.         bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  64.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  65.  
  66.         color_prom++;
  67.     }
  68.  
  69.     color_prom += 2*Machine->drv->total_colors;
  70.     /* color_prom now points to the beginning of the character lookup table */
  71.  
  72.  
  73.     /* characters use colors 240-255 */
  74.     for (i = 0;i < TOTAL_COLORS(0);i++)
  75.         COLOR(0,i) = (*(color_prom++) & 0x0f) + 240;
  76.  
  77.     /* sprites use colors 0-256 (?) in 16 banks */
  78.     for (i = 0;i < TOTAL_COLORS(1)/16;i++)
  79.     {
  80.         int j;
  81.  
  82.  
  83.         for (j = 0;j < 16;j++)
  84.             COLOR(1,i + j * TOTAL_COLORS(1)/16) = (*color_prom & 0x0f) + 16 * j;
  85.  
  86.         color_prom++;
  87.     }
  88. }
  89.  
  90.  
  91. WRITE_HANDLER( sbasketb_flipscreen_w )
  92. {
  93.     if (flipscreen != data)
  94.     {
  95.         flipscreen = data;
  96.         memset(dirtybuffer,1,videoram_size);
  97.     }
  98. }
  99.  
  100.  
  101. /***************************************************************************
  102.  
  103.   Draw the game screen in the given osd_bitmap.
  104.   Do NOT call osd_update_display() from this function, it will be called by
  105.   the main emulation engine.
  106.  
  107. ***************************************************************************/
  108. void sbasketb_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  109. {
  110.     int offs,i;
  111.     int sx,sy,code,color,flipx,flipy;
  112.  
  113.  
  114.     /* for every character in the Video RAM, check if it has been modified */
  115.     /* since last time and update it accordingly. */
  116.     for (offs = videoram_size - 1;offs >= 0;offs--)
  117.     {
  118.         if (dirtybuffer[offs])
  119.         {
  120.             dirtybuffer[offs] = 0;
  121.  
  122.             sx = offs % 32;
  123.             sy = offs / 32;
  124.  
  125.             code  = videoram[offs] + ((colorram[offs] & 0x20) << 3);
  126.             color = colorram[offs] & 0x0f;
  127.             flipx = colorram[offs] & 0x40;
  128.             flipy = colorram[offs] & 0x80;
  129.  
  130.             if (flipscreen)
  131.             {
  132.                 flipx = !flipx;
  133.                 flipy = !flipy;
  134.  
  135.                 sx = 31 - sx;
  136.                 sy = 31 - sy;
  137.             }
  138.  
  139.             drawgfx(tmpbitmap,Machine->gfx[0],
  140.                     code, color,
  141.                     flipx, flipy,
  142.                     8*sx,8*sy,
  143.                     &scroll_area,TRANSPARENCY_NONE,0);
  144.         }
  145.     }
  146.  
  147.  
  148.     /* copy the temporary bitmap to the screen */
  149.     {
  150.         int scroll[32];
  151.  
  152.         if (!flipscreen)
  153.         {
  154.             for (i = 0;i < 6;i++)
  155.                 scroll[i] = 0;
  156.  
  157.             for (i = 6;i < 32;i++)
  158.                 scroll[i] = -*sbasketb_scroll - 1;
  159.         }
  160.         else
  161.         {
  162.             for (i = 26;i < 32;i++)
  163.                 scroll[i] = 0;
  164.  
  165.             for (i = 0;i < 26;i++)
  166.                 scroll[i] = *sbasketb_scroll + 1;
  167.         }
  168.  
  169.         copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  170.     }
  171.  
  172.     /* Draw the sprites */
  173.     offs = (*sbasketb_spriteram_select & 0x01) * 0x100;
  174.  
  175.     for (i = 0; i < 64; i++, offs += 4)
  176.     {
  177.         sx = spriteram[offs + 2];
  178.         sy = spriteram[offs + 3];
  179.  
  180.         if (sx || sy)
  181.         {
  182.             code  =  spriteram[offs + 0] | ((spriteram[offs + 1] & 0x20) << 3);
  183.             color = (spriteram[offs + 1] & 0x0f) + 16 * *sbasketb_palettebank;
  184.             flipx =  spriteram[offs + 1] & 0x40;
  185.             flipy =  spriteram[offs + 1] & 0x80;
  186.  
  187.             if (flipscreen)
  188.             {
  189.                 flipx = !flipx;
  190.                 flipy = !flipy;
  191.  
  192.                 sx = 240 - sx;
  193.                 sy = 240 - sy;
  194.             }
  195.  
  196.             drawgfx(bitmap,Machine->gfx[1],
  197.                     code, color,
  198.                     flipx, flipy,
  199.                     sx, sy,
  200.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  201.         }
  202.     }
  203. }
  204.